<?php
/**
 * [商网通 System] Copyright swtshop.cn
 * QQ: 1170787711
 * Author: gj.name
 * This is NOT a freeware
*/
include '../../UQframework/core/process.php';
include 'pay.class.php';
$browser = cfg('browser');
if ($browser == 'pc') {
    $paycfg = payment_config('wxpay', 'pc');
    $paycfg['support'] = 'pc';
} elseif ($browser == 'wchat') {
    $paycfg = payment_config('wxpay', 'wchat');
    $paycfg['support'] = 'wap';
} else {
    exit('不支持此交易');
}
$post_data = $GLOBALS['HTTP_RAW_POST_DATA'];
$pcls = new pay_wxpay($paycfg);
$p_result = $pcls->wx_xml_to_array($post_data);
$param = array('appid' => $paycfg['appid'], 'mch_id' => $paycfg['mch_id'], 'transaction_id' => $p_result['transaction_id']);
$result = $pcls->pay_status($param);
if ($result['result_code'] == 'SUCCESS') {
    $out_trade_no = $result['out_trade_no'];
    $ps = new pay('wxpay');
    $row = $ps->pay_run($out_trade_no);
    if ($row['id']) {
        exit('ACCESS');
    } else {
        exit('FILE');
    }
}